import java.util.Arrays;
import java.util.Comparator;

/**
 * @program: LeetCode
 * @description: LeetCode : 179. 最大数
 * @author: WXY
 * @create: 2023-01-03 17:07
 * @Version 1.0
 **/
public class Num179_largestNumber {
    public static String largestNumber(int[] nums) {
        Integer[] arr = new Integer[nums.length];
        for (int i = 0; i < nums.length; i++) {
            arr[i] = nums[i];
        }
        Arrays.sort(arr, new myCompararot());
        String str = "";
        if (arr[0] == 0) {
            return "0";
        }
        for (Integer s : arr) {
            str += s;
        }
        return str;
    }

    public static void main(String[] args) {
        int[] arr = {3, 30, 34, 5, 9};
        String i = largestNumber(arr);
        System.out.println(i);
    }

    public static class myCompararot implements Comparator<Integer> {
        @Override
        public int compare(Integer o1, Integer o2) {
            String s1 = o1.toString();
            String s2 = o2.toString();
            return (s2 + s1).compareTo(s1 + s2);
        }
    }
}
